//
//  ExpandCell.m
//  ExpandCellDemo
//
//  Created by Derek on 16/7/12.
//  Copyright © 2016年 huangxu. All rights reserved.
//

#import "ExpandCell.h"
#import "TableViewController.h"

@implementation ExpandCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

- (void)setShowStr:(NSString *)showStr {
    _showStr = showStr;
    _lbShowText.text = _showStr;
    if ([self heightWithText:_showStr] <= defalutLabelHeight) {
        _btnExpand.hidden = YES;
    }else{
        _btnExpand.hidden = NO;
    }
}
- (float)heightWithText:(NSString*)text {
    
    CGFloat lbContentWidth   = self.bounds.size.width - 25.f;
    CGSize lbContentmaxSize  = CGSizeMake(lbContentWidth, MAXFLOAT);
    NSDictionary * attribute = @{NSFontAttributeName : [UIFont systemFontOfSize:15.f]};
    CGRect rect = [text boundingRectWithSize:lbContentmaxSize
                                     options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                  attributes:attribute
                                     context:nil];
    return rect.size.height;
}


- (IBAction)btnExpand:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(didTapExpandButton:)]) {
        [_delegate didTapExpandButton:self];
    }
}

@end
